<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Custom_View_Helper_Facebook extends Zend_View_Helper_Abstract
{
	public function facebook()
	{
		$facebook = Zend_Registry::get('facebook');
		?>
			<div style="display: none" id="fb-root"></div>
			<script>
			  window.fbAsyncInit = function() {
				FB.init({
				  appId   : '<?php echo $facebook->getAppId(); ?>',
				  session : <?php echo json_encode($facebook->getSession()); ?>, 
				  status  : true, 
				  cookie  : true, 
				  xfbml   : true 
				});

				// whenever the user logs in, we refresh the page
				FB.Event.subscribe('auth.login', function() {
				  window.location.reload();
				});

				// when the user logout we also logout it from our system
				FB.Event.subscribe('auth.logout', function() {
				  window.location.href = '<?php echo '/user/auth/logout'; ?>';
				});

			  };

			  (function() {
				var e = document.createElement('script');
				e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
				e.async = true;
				document.getElementById('fb-root').appendChild(e);
			  }());
			</script>
	  <?php
	}
}
?>
